package com.cqtczh.qhd.driver.acticity;

import java.io.File;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javabeen.ReceiveOrderMessageBeen;

import org.apache.http.conn.ssl.SSLSocketFactory;

import sslSocketFactory.CustomerSocketFactory;

import httptools.HttpJsonTool;
import httptools.HttpTools;
import httptools.HttpTools.DownLoadCallBack;
import httptools.HttpsUtils;

import View.TouchMoveAction;
import View.TouchMoveToZoomScrollView;
import android.accounts.Account;
import android.accounts.OnAccountsUpdateListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.google.gson.reflect.TypeToken;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.cqtczh.qhd.driver.R;
import com.cqtczh.qhd.driver.acticity.base.BaseActivity;
import com.cqtczh.qhd.driver.api.GagApi;
import com.cqtczh.qhd.driver.model.CargoInfo;
import com.cqtczh.qhd.driver.utils.OrderSoundRecorder;

/**
 * * @author 作者 陈修园:
 * 
 * @date 创建时间：2015-5-25 下午2:06:06
 * @version 1.0
 * @parameter
 * @since
 * @return
 */
/*
 * 
 * 自定义控件
 */
public class test extends BaseActivity {

	private TouchMoveAction scrollView;
	private String[] adapterData;
	private OrderSoundRecorder orderSoundRecorder;

	private String orderId = "1", userId = "1", type = "2", Price = "300";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.delete_test);
		orderSoundRecorder=new OrderSoundRecorder(this);
		Button button1 = (Button) findViewById(R.id.button1);
		Button button2 = (Button) findViewById(R.id.button2);
		Button button3 = (Button) findViewById(R.id.button3);
		Button button4 = (Button) findViewById(R.id.button4);
		Button button5=(Button) findViewById(R.id.button5);
		button5.setOnTouchListener(new OnTouchListener() {
			
			@Override
			public boolean onTouch(View arg0, MotionEvent ev) {
				// TODO Auto-generated method stub
				
				
				if (ev.getAction()==MotionEvent.ACTION_DOWN) {
					RecoderSound(true);
				}
				if (ev.getAction()==MotionEvent.ACTION_UP) {
					RecoderSound(false);
				}
				
				return false;
			}
		});
		button1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Log.v("点了", "点了");
				OrderMessageSoundexchange();
			}
		});
		button2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				rejectOrder();
			}
		});
		button3.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				transportOrder();
			}
		});
		button4.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				AcceptOrder();
			}
		});
	}

	/*
	 * ************************************新服务器新功能*******************************
	 * ************************************
	 */
	/**
	 * 订单议价功能
	 */
	private void OrderMessageSoundexchange() {

		ReceiveOrderMessageBeen receiveOrderMessageBeen = new ReceiveOrderMessageBeen();
		List<String> files = new ArrayList<String>();
		Log.v("OrderMessageSoundexchange", "");
		String url;
		
			
			Log.v("OrderMessageSoundexchange", "");
		//	receiveOrderMessageBeen.setFileName(receiveOrderMessageBeen
		//			.getFileName());
			// http://192.168.1.113:8080/cqtczh/fleets/sendMsgWithFile
			url = "http://192.168.1.113:8080/cqtczh/fleets/sendMsgWithFile";
			receiveOrderMessageBeen.setOrderId("1");
			receiveOrderMessageBeen.setType("1");
			receiveOrderMessageBeen.setReceiver("2");
			receiveOrderMessageBeen.setSender("22222222");
			receiveOrderMessageBeen.setSendertype("1");
			receiveOrderMessageBeen.setReceivertype("2");
			receiveOrderMessageBeen.setBargetprice("300");
			receiveOrderMessageBeen.setContent("老板多加200块钱我就送!!!");
			HttpJsonTool httpJsonTool = new HttpJsonTool(this);
			httpJsonTool.SetOnLister(new Handler() {
				@Override
				public void handleMessage(Message msg) {
					// TODO Auto-generated method stub
					super.handleMessage(msg);
					if (msg.what == 1) {
						// files=null;
						Toast.makeText(test.this, "你的信息已经发送给货主",
								Toast.LENGTH_LONG).show();
					}
				}
			});

			if ((orderSoundRecorder.GetSonunFileName().length() > 0)
					&& (orderSoundRecorder.GetSonunFileName() != null)) {
				files.add(orderSoundRecorder.GetSonunFileName());
			}
		//	httpJsonTool.StartWork(receiveOrderMessageBeen, url, null, files);
			// HTTPStartwork(url,receiveOrderMessageBeen,orderSoundRecorder.GetSonunFileName());
		

	}

	/**
	 * 取消订单功能 orderId 订单ID Stirng userId 用户的ID String type 用户类型 String
	 * 
	 * 
	 * 
	 * 
	 */
	private void rejectOrder() {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("orderId", orderId);
		map.put("userId", userId);
		map.put("type", type);
		HttpJsonTool httpJsonTool = new HttpJsonTool(this);
		httpJsonTool.SetOnLister(new Handler() {
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				if (msg.what == 1) {
					Log.v("取消完成", "取消完成");
					Toast.makeText(test.this, "取消完成", Toast.LENGTH_LONG).show();
				}
			}
		});
		httpJsonTool.StartWork(map,
				"http://192.168.1.113:8080/cqtczh/fleets/rejectOrder", null,
				null);

	}

	/**
	 * 转单功能
	 * 
	 * orderId 订单ID Stirng userId 用户的ID String type 用户类型 String
	 * 
	 * 
	 * 
	 */

	private void transportOrder() {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("orderId", orderId);
		map.put("userId", userId);
		map.put("type", type);
		HttpJsonTool httpJsonTool = new HttpJsonTool(this);
		httpJsonTool.SetOnLister(new Handler() {
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				if (msg.what == 1) {
					Log.v("转单完成", "转单完成");
					Toast.makeText(test.this, "转单完成", Toast.LENGTH_LONG).show();
				}
			}
		});
		httpJsonTool.StartWork(map,
				"http://192.168.1.113:8080/cqtczh/fleets/transportOrder", null,
				null);

	}

	/**
	 * 确认订单 orderId 订单ID Stirng Price 最终定价 Stirng userId 用户的ID String type 用户类型
	 * String
	 */
	private void AcceptOrder() {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("orderId", orderId);
		map.put("price", Price);
		map.put("userId", userId);
		map.put("type", type);
		HttpJsonTool httpJsonTool = new HttpJsonTool(this);
		httpJsonTool.SetOnLister(new Handler() {
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				if (msg.what == 1) {
					Log.v("订单完成", "订单完成");
					Toast.makeText(test.this, "订单完成", Toast.LENGTH_LONG).show();
				}
			}
		});
		httpJsonTool.StartWork(map,
				"http://192.168.1.113:8080/cqtczh/fleets/confirmOrder", null,
				null);
	}

	/**
	 * 记录声音
	 */
	private void RecoderSound(boolean flag) {

		if (flag) {
			orderSoundRecorder.StartRecorder();

		} else if (orderSoundRecorder != null) {

			orderSoundRecorder.StopRecorder();
		} else {
			Toast.makeText(this, "声音录制器为空", Toast.LENGTH_LONG).show();
		}

	}

	/*
	 * ************************************新服务器新功能*******************************
	 * ************************************
	 */
}